<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of CookieTypeDao
 *
 * @author Nhân
 */

require_once 'DbConnection.php';

class CookieTypeDao {
    public function addCookieType($cookieType) {
        $conn = DbConnection::getInstance()->openConnection();
        if ($conn != null) {
            $strQuery = "INSERT INTO CookieType (`typeName`, `typeImage`) VALUES ('" . $cookieType->getTypeName() . "', '" . $cookieType->getTypeImage() . "')";
            if (!mysql_query($strQuery)) {
                echo "Hix hix";
            }
        }
        DbConnection::getInstance()->closeConnection();
    }
    
    public function updateCookieType($cookieType) {
        $conn = DbConnection::getInstance()->openConnection();
        if ($conn != null) {
            $strQuery = "UPDATE `CookieType` SET `typeName` = `" . $cookieType->getTypeName() . "`, `typeImage` = `" . $cookieType->getTypeImage() . "` WHERE `id` = `" . $cookieType->getId() . "`";
            mysql_query($strQuery, $conn);
        }
        DbConnection::getInstance()->closeConnection();
    }
    
    public function getAllCookieType() {
        $conn = DbConnection::getInstance()->openConnection();
        $result = array();
        if ($conn != null) {
            $strQuery = "SELECT * FROM `CookieType`";
            $rows = mysql_query($strQuery, $conn);
            
            while($row = mysql_fetch_array($rows)){
                $cookieType = new CookieType();
                $cookieType->setId($row['id']);
                $cookieType->setTypeName($row['typeName']);
                $cookieType->setTypeImage($row['typeImage']);
                $result[] = $cookieType;
            }
   
        }
        DbConnection::getInstance()->closeConnection();
        return $result;
    }
}

?>
